<?php
class mstraccountcontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('masterbank_model');
		$this->load->model('mstraccount_model');
		$this->load->library('session');
		$this->load->library('pagination_editable');
		if(($this->session->userdata('fullname') == '') || ($this->session->userdata('fullname') == NULL)){
			redirect('logincontroller');
		}
	}
	
	function index()
	{        
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('mstraccountcontroller/index');
		$config['total_rows'] = $this->mstraccount_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		if (isset($_POST['btnview'])) 
		{
			if($_POST['kdbankview'] == "0")
			{         
				$dataprofile = array(
					'page_title' => 'Finance > Account Bank',
					'name' => $this->session->userdata('fullname'),
					'masterbank' => $this->masterbank_model->getListbank(),
					'masteraccount' => $this->mstraccount_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links(),
					'message' =>''	
				);	
			}
			else if($_POST['kdbankview'] == "1")
			{
				$this->mstraccount_model->setKodeBank($_POST['bankview']);
				$dataprofile = array(
					'page_title' => 'Finance > Account Bank',
					'name' => $this->session->userdata('fullname'),
					'masterbank' => $this->masterbank_model->getListbank(),
					'masteraccount' => $this->mstraccount_model->getkdbanklike(),
					'links' => $this->pagination_editable->create_links(),
					'message' =>''
				); 
			}
			else if($_POST['kdbankview'] == "2")
			{
				$this->mstraccount_model->setBankname($_POST['bankview']);
				$dataprofile = array(
					'page_title' => 'Finance > Account Bank',
					'name' => $this->session->userdata('fullname'),
					'masterbank' => $this->masterbank_model->getListbank(),
					'masteraccount' => $this->mstraccount_model->getnamabanklike(),
					'links' => $this->pagination_editable->create_links(),
					'message' =>''
				); 	
			}
			else if($_POST['kdbankview'] == "3")
			{
				$this->mstraccount_model->setNoRekening($_POST['bankview']);
				$dataprofile = array(
					'page_title' => 'Finance > Account Bank',
					'name' => $this->session->userdata('fullname'),
					'masterbank' => $this->masterbank_model->getListbank(),
					'masteraccount' => $this->mstraccount_model->getnorekeninglike(),
					'links' => $this->pagination_editable->create_links(),
					'message' =>''
				); 
			}
        } 
		else 
		{       
			$dataprofile = array(
				'page_title' => 'Finance > Account Bank',
				'name' => $this->session->userdata('fullname'),
				'masterbank' => $this->masterbank_model->getListbank(),
				'masteraccount' => $this->mstraccount_model->getListlimit($config['per_page'],$page),
				'links' => $this->pagination_editable->create_links(),
				'message' =>''		
			);	
		}
		$content = array(
			'content' => 'finance/bank/viewmstraccount'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}

    function getmstraccount() 
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('mstraccountcontroller/index');
		$config['total_rows'] = $this->mstraccount_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		$idkdbank = $this->uri->segment(3);
		$this->mstraccount_model->setKodeBank($idkdbank);

        $dataprofile = array(
            'page_title' => 'Finance > Account Bank',
            'name' => $this->session->userdata('fullname'),
			'masterbank' => $this->masterbank_model->getListbank(),
			'masteraccount' => $this->mstraccount_model->getListlimit($config['per_page'],$page),
			'links' => $this->pagination_editable->create_links(),
			'message' =>''	
            /*'individulist' => $this->Individu_model->getOneSelect(),
            'wilayahlist' => $this->Wilayah_model->getWilayahList(),
            'status_nikah' => $this->Statusnikah_model->getStatusNikahList(),
            'foto' => $this->Individu_model->get_images(),
            'role' => $this->session->userdata('role')*/
        );
        $content = array(
            'content' => 'finance/bank/viewmstraccount'
        );
        $this->template->load('template/default', $content, $dataprofile);
    }
	
	function tambahmstraccount()
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('mstraccountcontroller/index');
		$config['total_rows'] = $this->mstraccount_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
        if (isset($_POST['btnSave'])) 
		{
            if (isset($_POST['kdbank']) &&
                    isset($_POST['sldawal']) &&
					isset($_POST['sldakhir']) &&
                    !($_POST['kdbank'] == '') &&
					!($_POST['sldawal'] == '') &&
                    !($_POST['sldakhir'] == '')) 
			{
	            $this->mstraccount_model->setKodeBank($_POST['kdbank']);
                $this->mstraccount_model->setSaldoAwal($_POST['sldawal']);
                $this->mstraccount_model->setSaldoAkhir($_POST['sldakhir']);
			   	$this->mstraccount_model->setCreatedBy($this->session->userdata('userid'));
			   	$tanggal=date('Y-m-d H:i:s', strtotime('now'));
				$this->mstraccount_model->setCreatedOn($tanggal);
				
				$this->mstraccount_model->insert();
				
                redirect('mstraccountcontroller');
            } else {
                $dataprofile = array(
					'page_title' => 'Finance > Account Bank',
            		'name' => $this->session->userdata('fullname'),
					'masterbank' => $this->masterbank_model->getListbank(),
					'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Lengkapi Form Di Bawah Untuk Menambah Account Bank </div>',
					'masteraccount' => $this->mstraccount_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links()
                    
					/*'page_title' => 'Tambah Data Individu',
                    'name' => $this->session->userdata('name'),
                    'role' => $this->session->userdata('role'),
                    'wilayahlist' => $this->Wilayah_model->getWilayahList(),
                    'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Lengkapi Form Di Bawah Untuk Menambah Individu Jema\'at</div>',
                    'status_nikah' => $this->Statusnikah_model->getStatusNikahList()*/
                );
                $content = array(
                    'content' => 'finance/bank/viewmstraccount'
                );
                $this->template->load('template/default', $content, $dataprofile);
            }
        } else {
           $dataprofile = array(
			'page_title' => 'Finance > Account Bank',
			'name' => $this->session->userdata('fullname'),
			'masterbank' => $this->masterbank_model->getList(),
			'masteraccount' => $this->mstraccount_model->getListlimit($config['per_page'],$page),
			'links' => $this->pagination_editable->create_links(),
			'message' =>''	
			);		
			$content = array(
				'content' => 'finance/bank/viewmstraccount'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }
	
    function ubahmstraccount() 
	{
        $idkdbank = $this->uri->segment(3);
		$this->mstraccount_model->setKodeBank($idkdbank);
        if (isset($_POST['btnSave'])) {
			$this->mstraccount_model->setKodeBank($_POST['kdbank']);
			$this->mstraccount_model->setSaldoAwal($_POST['sldawal']);
			$this->mstraccount_model->setUangmasuk($_POST['uangin']);
			$this->mstraccount_model->setUangkeluar($_POST['uangout']);
			$this->mstraccount_model->setSaldoAkhir($_POST['sldakhir']);
			$this->mstraccount_model->setLastUpdateBy($this->session->userdata('userid'));
			$tanggal=date('Y-m-d H:i:s', strtotime('now'));
			$this->mstraccount_model->setLastUpdateOn($tanggal);
			
            $this->mstraccount_model->ubahmstraccount();

            redirect('mstraccountcontroller');
        } else {
            $this->mstraccount_model->setKodeBank($idkdbank);
            $dataprofile = array(
			'page_title' => 'Finance > Account Bank',
			'name' => $this->session->userdata('fullname'),
			'masteraccount' => $this->mstraccount_model->getkdaccount()			
			);		
			$content = array(
				'content' => 'finance/bank/editmstraccount'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }

    function deletemstraccount() 
	{
        $KodeBank = $this->uri->segment(3);
        $this->mstraccount_model->setKodeBank($KodeBank);
        $this->mstraccount_model->deletemstraccount();
        redirect('mstraccountcontroller');
    }
	
	function getnorekening() 
	{
        $KodeBank = $this->uri->segment(3);
        $dataprofile = array(
			'page_title' => 'Finance > Account Bank',
			'name' => $this->session->userdata('fullname'),
			'masterbank' => $this->masterbank_model->getkdbank()		
		);		
		$content = array(
			'content' => 'finance/bank/viewmstraccount'
		);
		$this->template->load('templates/default',$content,$dataprofile);
    }
}